package com.loong.life.controller.backend;

import com.loong.common.mvc.BaseBackendController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.life.common.backend.param.AgentProductParam;
import com.loong.life.common.backend.param.AgentProductQueryParam;
import com.loong.life.handler.AgentProductHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 处理有关代理商产品请求的controller
 * @Author: 刘群
 * @Date: 2020/11/26 16:42
 */
@RestController
@RequestMapping("manage/life/agentProduct")
public class AgentProductController extends BaseBackendController {

    @Resource
    private AgentProductHandler productHandler;

    /**
     * 新增代理商产品
     * @param param 产品参数
     * @return 响应的结果
     */
    @PostMapping("save")
    public Result saveAgentProduct(@Validated({CommonInsert.class}) AgentProductParam param){
        param.setId(null);
        return handlerExecutor.execute(() -> productHandler.saveAgentProduct(param));
    }

    /**
     * 更新代理商产品
     * @param param 产品参数
     * @return 响应的结果
     */
    @PostMapping("update")
    public Result updateAgentProduct(@Validated({CommonUpdate.class}) AgentProductParam param){
        return handlerExecutor.execute(() -> productHandler.updateAgentProduct(param));
    }

    /**
     * 批量删除代理商产品
     * @param idList 产品id
     * @return 响应的结果
     */
    @PostMapping("batchDelete")
    public Result batchDeleteAgentProduct(@RequestParam("idList")List<Long> idList){
        return handlerExecutor.execute(() -> productHandler.batchDeleteAgentProduct(idList));
    }

    /**
     * 分页查询代理商产品
     * @param param 查询参数
     * @return 响应的结果
     */
    @PostMapping("pageQuery/agentProductList")
    public Result pageQueryAgentProduct(AgentProductQueryParam param){
        return handlerExecutor.execute(() -> productHandler.pageQueryAgentProduct(param));
    }


}
